﻿using MediatR;
using TaskProject.Application.Command.BOM;
using TaskProject.Domain.BOM;
using TaskProject.ErrorCode;
using TaskProject.InfrasIntructure.Interface;

namespace TaskProject.Application.Handler.BOM
{
    public class GetMaterialHandler : IRequestHandler<GetMaterialCommand, APIResult<List<MaterialModel>>>
    {
        IBaseRepository<MaterialModel> materRepo;

        public GetMaterialHandler(IBaseRepository<MaterialModel> materRepo)
        {
            this.materRepo = materRepo;
        }

        public Task<APIResult<List<MaterialModel>>> Handle(GetMaterialCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<MaterialModel>> res = new APIResult<List<MaterialModel>>();
            var materials=materRepo.GetAll().Where(c=>!c.IsDel).ToList();
            res.Msg = "查询物料配件成功";
            res.Code=APIEnum.Success;
            res.Data = materials;
            return Task.FromResult(res);
        }
    }
}
